package com.itheima.controller.backend.Service.ServiceImpl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.DTO.OrderDTO;
import com.itheima.VO.OrderVO;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.controller.backend.Service.OrderService;
import com.itheima.mapper.OrderMapper;
import com.itheima.pojo.Order;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;


    @Override
    public PageResult findPage(QueryPageBean queryPageBean){
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        List<OrderVO> orderList = orderMapper.findPage(queryPageBean);
        for (OrderVO orderVO : orderList) {
            orderVO.setName(orderMapper.findMemberByMemberId(orderVO.getMemberId()));
            orderVO.setPhoneNumber(orderMapper.findPhoneNumberByMemberId(orderVO.getMemberId()));
            orderVO.setCode(orderMapper.findSetmealCodeBySetmealId(orderVO.getSetmealId()));
        }
        Page page = (Page) orderList;
        return new PageResult(page.getTotal(),page.getResult());
    }

    public void update(OrderDTO orderDTO){
        orderMapper.updataOrderStatus(orderDTO);
    }
}
